import threading
import time
from techlego_sdk import binary_protocol, scan3d_client,collect_parameters,marks_erasing
import os
import paramiko

class Scanner:
    def __init__(self):
        soft_path = "\"D:\\Program Files\\Techlego\\Techlego\\Techlego.exe\""
        t = threading.Thread(target=os.system, args=(soft_path,))
        t.daemon = True
        t.start()
        # os.system(soft_path)
        time.sleep(3)
        protocol = binary_protocol("localhost", 5252)
        # 通过协议创建客户端
        client = scan3d_client(protocol)
        # 设置快速扫描
        obj = collect_parameters()
        obj.set_fast_scan(True, True)
        # 设置
        client.collect_params_window_set(obj)
        # 打开相机
        client.open_camera(0)

        # 根据项目文件打开项目，项目文件不存在会失败
        # 开始扫描
        self.client = client

        # self.ssh = paramiko.SSHClient()
        # self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        # self.ssh.connect(hostname='192.168.215.49', username='WRW', password='qwer')


    def save(self,file_name):
        # asc
        self.client.save_project()
        # self.client.
        me = marks_erasing()
        me.set_enable(True)
        self.client.export_window_set_marks_erasing(me)
        self.client.process_data()
        self.client.export_point_cloud_file(file_name)

    # source_file = 'task.py'
    # target_folder = 'E:\\taskbb.py'
    def send_to_server(self,source_file, target_folder):
        sftp = self.ssh.open_sftp()
        sftp.put(source_file, target_folder)  # 目标文件名可以按需更改
        sftp.close()
        # 关闭SSH连接

# 设置源文件路径和目标路径

# 使用SFTP传输文件
